package com.kingwang.study.spring.security.demo.security.token.session;

import lombok.Getter;
import lombok.Setter;

import java.time.LocalDateTime;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 抽象TokenSession，用于存放公共方法逻辑
 *
 * @author King
 */
public abstract class AbstractTokenSession implements TokenSession {
    @Getter
    @Setter
    private String username;

    @Getter
    @Setter
    private LocalDateTime lastActiveTime;

    @Getter
    private Map<String, String> attributes = new ConcurrentHashMap<>();

    @Override
    public String getAttribute(String name) {
        return this.attributes.get(name);
    }

    @Override
    public void setAttribute(String name, String value) {
        this.attributes.put(name, value);
    }

    @Override
    public void removeAttribute(String name) {
        this.attributes.remove(name);
    }

    @Override
    public void clearAttributes() {
        this.attributes.clear();
    }

}